package service;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import dao.InviteDao;
import dao.SearchDao;
import po.Employment;
import po.Order;
import po.User;

public class SearchService {
	private List<Employment> list;
	private Map<String, Object> request, session;
	//显示全部的招聘信息
	public boolean getAllEmployment() {
		ActionContext ctx= ActionContext.getContext();
		session=(Map) ctx.getSession();
		request=(Map) ctx.get("request");
		String hql = "from Employment as emp where status=0";
		InviteDao dao = new InviteDao();
		list = dao.findByHql(hql);
		if(list.isEmpty()) {
			return false;
		}
		//由返回数组得到部分统计信息---不完整
		int number = list.size(); //当前课程总数
		int math = 0;
		int english = 0;
		int china = 0;
		for(int i=0;i<list.size();i++) {
			if(list.get(i).getCourse().equals("数学")) {
				math++;
			}
			if(list.get(i).getCourse().equals("语文")) {
				china++;
			}
			if(list.get(i).getCourse().equals("英语")) {
				english++;
			}
		}
		request.put("tip", "共收录："+number+"条招聘信息");
		return true;
	}
	//筛选招聘信息
	public boolean searchEmployment(Employment emp) {
		String type = emp.getType(); //年级
		String course = emp.getCourse(); //课程
		String background = emp.getBackground(); //学历要求
		String sex = emp.getSex(); //性别
		
		String hql = "from Employment as emp where type=" + "'"
				+type+"' and course='"+course+"' and sex='"+sex+"' and background='"+background+ "' and status=0";
		SearchDao dao = new SearchDao();
		list = dao.findByHql(hql);
	
		return true;
	}
	//由招聘信息的id号查询发布者的信息
	public User searchUserByEmpID(int empID) {
		//System.out.println("传入的empID："+empID);
		SearchDao dao = new SearchDao();
		Employment emp = (Employment)dao.findEmpInfo(empID);
		int userID = emp.getCostomerID();
		User user = (User)dao.findUserInfo(userID);
		return user;
	}
	//由招聘信息的id号查询该招聘信息具体信息
	public Employment searchEmpByEmpID(int empID) {
		SearchDao dao = new SearchDao();
		Employment emp = (Employment)dao.findEmpInfo(empID);
		return emp;
	}
	//由订单的id号查询订单发布者的信息
	public User searchIssueInfo(int orderID) {
		SearchDao dao = new SearchDao();
		Order ord = (Order)dao.findOrderInfo(orderID);
		int tutorID = ord.getPromulgatorID();
		User user = (User)dao.findUserInfo(tutorID);
		return user;
	}
	//由订单id号查询订单申请者的申请信息
	public User searchApplyInfo(int orderID) {
		SearchDao dao = new SearchDao();
		Order ord = (Order)dao.findOrderInfo(orderID);
		int userID = ord.getCostomerID();
		User user = (User)dao.findUserInfo(userID);
		return user;
	}
	
	
	
	public List getList() {
		return this.list;
	}
}
